package com.lee.dhsg.dao.provider;

/**
 * @author Jun
 */
import java.util.Map;

import org.apache.ibatis.jdbc.Null;
import org.apache.ibatis.jdbc.SQL;

import com.lee.dhsg.domain.Student;

public class StudentSqlProvider {

	/**
	 * 动态查询学生
	 * @param params
	 * @return
	 */
	public String selectWhitParam(Map<String, Object> params) {
		return new SQL() {
			{
				SELECT("*");
				FROM("student");
				if (params.get("student") != null) {
					Student student = (Student) params.get("student");
					if (student.getUsername() != null && !student.getUsername().equals("")) {
						WHERE("username=#{student.username}");
					}
					if (student.getRealname() != null && !student.getRealname().equals("")) {
						WHERE("realname LIKE CONCAT ('%',#{student.realname},'%') ");
					}
					if(student.getiDCardNum()!=null&&!student.getiDCardNum().equals("")){
						WHERE("IDCardNum LIKE CONCAT('%',#{student.iDCardNum},'%')");
					}
					if(student.getSex()!=null&&!student.getSex().equals("")){
						WHERE("sex=#{student.sex}");
					}
					if(student.getRealnameStatus()!=null&&!student.getRealnameStatus().equals("")){
						WHERE("realnameStatus=#{student.realnameStatus}");
					}
					if(student.getCheckStatus()!=null&&!student.getCheckStatus().equals("")){
						WHERE("checkStatus=#{student.checkStatus}");
					}
				}
			}
		}.toString();
	}

	/**
	 * 动态插入学生
	 *
	 * @param student
	 */
	public String insertStudent(Student student) {
		return new SQL() {
			{
				INSERT_INTO("student");
				if (student.getUsername() != null && !student.getUsername().equals("")) {
					VALUES("username", "#{username}");
				}
				if (student.getPassword() != null && !student.getPassword().equals("")) {
					VALUES("password", "#{password}");
				}
				if (student.getRealname() != null && !student.getRealname().equals("")) {
					VALUES("realname", "#{realname}");
				}
				if (student.getiDCardNum() != null && !student.getiDCardNum().equals("")) {
					VALUES("IDCardNum", "#{iDCardNum}");
				}
				if (student.getiDCardImg01() != null && !student.getiDCardImg01().equals("")) {
					VALUES("IDCardImg01", "#{iDCardImg01}");
				}
				if (student.getiDCardImg02() != null && !student.getiDCardImg02().equals("")) {
					VALUES("IDCardImg02", "#{iDCardImg02}");
				}
				if (student.getiDCardVideo() != null && !student.getiDCardVideo().equals("")) {
					VALUES("IDCardVideo", "#{iDCardVideo}");
				}
				if (student.getSex() != null && !student.getSex().equals("")) {
					VALUES("sex", "#{sex}");
				}
				if (student.getIcon() != null && !student.getIcon().equals("")) {
					VALUES("icon", "#{icon}");
				}
				if (student.getSignatrue() != null && !student.getSignatrue().equals("")) {
					VALUES("signatrue", "#{signatrue}");
				}
				if (student.getDescription() != null && !student.getDescription().equals("")) {
					VALUES("description", "#{description}");
				}
				if (student.getTel() != null && !student.getTel().equals("")) {
					VALUES("tel", "#{tel}");
				}
				if (student.getEmail() != null && !student.getEmail().equals("")) {
					VALUES("email", "#{email}");
				}
				if (student.getLastlogin() != null && !student.getLastlogin().equals("")) {
					VALUES("lastlogin", "#{lastlogin}");
				}
				if (student.getRealnameStatus() != null && !student.getRealnameStatus().equals("")) {
					VALUES("realnameStatus", "#{realnameStatus}");
				}
				if (student.getCheckStatus() != null && !student.getCheckStatus().equals("")) {
					VALUES("checkStatus", "#{checkStatus}");
				}
			}
		}.toString();
	}

	/**
	 * 动态更新学生
	 * @param student
	 * @return
	 */
	public String updateStudent(Student student){
		return new SQL(){
			{
				UPDATE("student");
				if (student.getRealname()!= null){
					SET("realname=#{realname}");
				}
				if (student.getiDCardNum()!= null){
					SET("IDCardNum=#{iDCardNum}");
				}
				if (student.getiDCardImg01()!= null){
					SET("IDCardImg01=#{iDCardImg01}");
				}
				if (student.getiDCardImg02()!= null){
					SET("IDCardImg02=#{iDCardImg02}");
				}
				if (student.getiDCardVideo()!= null){
					SET("IDCardVideo=#{iDCardVideo}");
				}
				if (student.getUsername()!= null){
					SET("username=#{username}");
				}
				if (student.getPassword()!= null){
					SET("password=#{password}");
				}
				if (student.getSex()!= null){
					SET("sex=#{sex}");
				}
				if (student.getIcon()!= null){
					SET("icon=#{icon}");
				}
				if (student.getSignatrue()!= null){
					SET("signatrue=#{signatrue}");
				}
				if (student.getDescription()!= null){
					SET("description=#{description}");
				}
				if (student.getTel()!= null){
					SET("tel=#{tel}");
				}
				if (student.getEmail()!= null){
					SET("email=#{email}");
				}
				if (student.getLastlogin()!= null){
					SET("lastlogin=#{lastlogin}");
				}
				if (student.getRealnameStatus()!= null){
					SET("realnameStatus=#{realnameStatus}");
				}
				if (student.getCheckStatus()!= null){
					SET("checkStatus=#{checkStatus}");
				}
				WHERE("sid=#{sid}");
			}
		}.toString();
	}
}
